package org.jetnuke.dao.sqlserver;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.List;

import net.jforum.JForumExecutionContext;
import net.jforum.util.preferences.SystemGlobals;

public class SqlServerBlogPostDAO extends org.jetnuke.dao.generic.GenericBlogPostDAO {

	public List retrievePublishByUser(int id, Calendar cal, int maxnumberpost) throws Exception {
		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("BlogPostModel.selectPublishByUserDateLimit");
		
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(q1+" "+maxnumberpost+" "+q2);
		
		p.setInt(1,id);
		p.setDate(2,new Date(cal.getTime().getTime()));
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}
	public List retrieveLast(int limit) throws Exception {
		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("BlogPostModel.selectLast");
		
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(q1+" "+limit+" "+q2);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}
	public List retrievePublishByUser(int id, int maxnumberpost) throws Exception {
		
		
		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("BlogPostModel.selectPublishByUserLimit");
		
		PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(q1+" "+maxnumberpost+" "+q2);
		
		p.setInt(1,id);
		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();
		
		return list;
	}
}
